if meson_build
    drivers_install_dir = meson.project_build_root() / 'opt/bmc/drivers'
else
    drivers_install_dir = 'opt/bmc/drivers/'
endif
run_command('mkdir', '-p', drivers_install_dir, check: false)

# mellanox接口源文件
mellanox_interface_sources = files(
  '../../../../../drivers/pcie_nic_card/mellanox/interface/board.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/network_adapter.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/network_port.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/optical_module.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/pcie_card.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/pcie_device.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/network_port/link_info.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/network_port/lldp_receive.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/network_port/metrics.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/network_adapter/cooling.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/optical_module/status.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/optical_module/cooling.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/optical_module/power.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/optical_module/voltage.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/optical_module/current.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/interface/pcie_device/bandwidth.cpp',
)

test_cx5_abi_sources = [
  '../../../../main.cpp',
  'test_cx5_abi.cpp',
]

test_cx5_card_sources = [
  '../../../../main.cpp',
  'test_cx5_card.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_card.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_port.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_om.cpp',
] + mellanox_interface_sources

test_cx5_port_sources = [
  '../../../../main.cpp',
  'test_cx5_port.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_port.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_card.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_om.cpp',
] + mellanox_interface_sources

test_cx5_om_sources = [
  '../../../../main.cpp',
  'test_cx5_om.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_om.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_card.cpp',
  '../../../../../drivers/pcie_nic_card/mellanox/cx5/cx5_port.cpp',
] + mellanox_interface_sources

test_cx5_abi = executable(
  'test_cx5_abi',
  test_cx5_abi_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox/cx5'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox'),
    include_directories('../../../../../drivers/internal'),
    include_directories('../../../../../include'),
    include_directories('../../../../../gen'),
    include_directories('../../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
  ],
  cpp_args: ['-DUNIT_TEST'],
  link_args: [
    '-Wl,-rpath,' + meson.project_build_root() + '/opt/bmc/drivers',
    '-Wl,-rpath,' + meson.project_build_root() + '/usr/lib64',
  ],
  install: false,
)

test_cx5_card = executable(
  'test_cx5_card',
  test_cx5_card_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox/cx5'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox'),
    include_directories('../../../../../drivers/internal'),
    include_directories('../../../../../include'),
    include_directories('../../../../../gen'),
    include_directories('../../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
    dev_deps,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
)

test_cx5_port = executable(
  'test_cx5_port',
  test_cx5_port_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox/cx5'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox'),
    include_directories('../../../../../drivers/internal'),
    include_directories('../../../../../include'),
    include_directories('../../../../../gen'),
    include_directories('../../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
    dev_deps,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
)

test_cx5_om = executable(
  'test_cx5_om',
  test_cx5_om_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox/cx5'),
    include_directories('../../../../../drivers/pcie_nic_card/mellanox'),
    include_directories('../../../../../drivers/internal'),
    include_directories('../../../../../include'),
    include_directories('../../../../../gen'),
    include_directories('../../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
    dev_deps,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
)

test('test_cx5_abi', test_cx5_abi, timeout: 300, suite: 'cx5', is_parallel: false,
     env: ['LD_LIBRARY_PATH=' + meson.project_build_root() + '/usr/lib64:' + meson.project_build_root() + '/opt/bmc/drivers:' + meson.project_build_root() + '/gen:' + meson.project_build_root() + '/drivers/internal:' + meson.project_build_root() + '/subprojects/libmcpp/src'])
test('test_cx5_card', test_cx5_card, timeout: 300, suite: 'cx5', is_parallel: false)
test('test_cx5_port', test_cx5_port, timeout: 300, suite: 'cx5', is_parallel: false)
test('test_cx5_om', test_cx5_om, timeout: 300, suite: 'cx5', is_parallel: false)
